function b=rrdir(namefilter, startpath)
%
%FUNCTION rrdir(namefilter,[startpath])
% namefilter = *?* filename filter
% startpath   = if not specified: pwd
%
% ~bcoe coe@queensu.ca 2010

if nargin<1
    help(mfilename)
    return
end
if nargin==1
    startpath=pwd;
end
if exist(startpath,'dir')~=7
    fprintf(' FUNCTION %s.m could not find ''%s'' \n',mfilename, startpath)
    startpath=pwd;
end

if 1%isempty(help('genpath_nosvn2'))  
    subfolders = textscan(genpath(startpath), '%s', 'delimiter', pathsep);subfolders=subfolders{:};
    char_loc=strfind(subfolders,[ filesep '.']); % remove '\.' folders that start with .
	cell_loc=cellfun(@(x) ~isempty(x), char_loc);
    subfolders(cell_loc)=[];
else
    subfolders = textscan(genpath_nosvn(startpath), '%s', 'delimiter', pathsep);subfolders=subfolders{:};%#ok<UNRCH> % removes *.svn folders so it will be faster
end

b=[];    
for i = 1:length(subfolders)
    a=dir([subfolders{i} filesep namefilter]);
    if ~isempty(a)
        %c=strcat(repmat([subfolders{i} filesep],size(a),1), {a.name}');
        %[a.name]=deal(c{:});
        [a(:).parentfolder]=deal([subfolders{i} filesep]);
        b=[b;a]; %#ok<AGROW>
    end % if ~isempty(a)
end % for i = 1:length(subfolders)

end % function
